<?php
// 同意取消预约
// header("content-type:text/html;charset=UTF-8");
include_once("conn.php");
include_once("d_getLoginInfo.php");

$orderID = $_GET["orderID"];

$select_sql = "SELECT * FROM order_infos WHERE orderID = '" . $orderID . "'";

if ($result_select = mysqli_query($connect_DB, $select_sql)) {
    $row_select = mysqli_fetch_object($result_select);
    $select_depart = "SELECT * FROM department_infos WHERE department_ID = '" . $row_select->orderType . "'";
    $result_depart = mysqli_query($connect_DB, $select_depart);
    $row_depart = mysqli_fetch_object($result_depart);
    //设置中国时区
    date_default_timezone_set('Asia/Shanghai');
    // 获取当前日期
    $getNowDate = date('Y-m-d');
    $insert_sql =
        "REPLACE INTO order_history_infos (order_ID,pet_ID,user_ID,doc_ID,order_Type,order_Remark,sub_Date,order_Date,over_Date,orderState)
        VALUES ('" . $row_select->orderID . "', '" . $row_select->pet_ID . "', '" . $row_select->user_ID . "', '" . $row_select->doc_ID . "',
        '" . $row_select->orderType . "-" . $row_depart->department_Name . "', '" . $row_select->orderRemark . "', '" . $row_select->subDate . "', '" . $row_select->orderDate . "', '" . $getNowDate . "', '-1')";
    if ($result_insert = mysqli_query($connect_DB, $insert_sql)) {
        $delete_sql = "DELETE FROM order_infos WHERE orderID = '" . $orderID . "'";
        if ($result_delete = mysqli_query($connect_DB, $delete_sql)) {
            echo "<script>alert('操作成功！');location='doc_AcceptInfo.php';</script>";
        } else {
            echo "<script>alert('操作失败！请重试！');location='doc_AcceptInfo.php';</script>";
            exit();
        }
    } else {
        echo "<script>alert('操作失败！请重试！');location='doc_AcceptInfo.php';</script>";
        exit();
    }
} else {
    echo "<script>alert('操作失败！请重试！');location='doc_AcceptInfo.php';</script>";
    exit();
}

$connect_DB->close();
?>